<?php


class AdminController {

    public function index() {
        if($_SESSION['is_logged'] == false || $_SESSION['user_data']['account_type'] !== 'admin') {
            header('Location: ?');
            exit;
        }

        include '../icloud_files/models/UserModel.php';
        $user = new UserModel();
        $user->get_currencies();

        $user->page_title = 'Admin Page';

        if($_SERVER['REQUEST_METHOD'] == 'GET' && count($_GET) > 5) {
            unset($_GET['p']);
            $user->update_currencies($_GET);
            if($user->messages['success']) {
                header('Location: ?p=admin');
            }
        }

        if($_SERVER['REQUEST_METHOD'] == 'POST') {
            include '../icloud_files/models/ServiceCentersModel.php';
            $center = new ServiceCentersModel();
            $center->add_auto_service_center($_POST, $_FILES);
            $user->messages = $center->messages;
        }

        include '../icloud_files/models/AdvModel.php';
        $adv = new AdvModel();
        $adv->get_all_ads();
        $adv->update_inactive();

        $user->adv_list = $adv->adv_list;
        $user->get_states();


        View::get_instance()->render('admin', $user);
    }
/* ------------------------------------------------------------------------------------------------- */

}